﻿using SFast.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SFast
{
    public static class ConvertExtensions
    {
        /// <summary>
        /// 时间戳转换成时间类型
        /// </summary>
        /// <param name="timestamp">时间戳</param>
        /// <returns></returns>
        public static DateTime _TimestampToDateTime(this long timestamp)
        {
            DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
            long lTime = long.Parse(timestamp + "0000000");
            TimeSpan toNow = new TimeSpan(lTime);

            return dateTimeStart.Add(toNow);

        }


        /// <summary>
        /// 时间类型转换时间戳
        /// </summary>
        /// <param name="dt">时间</param>
        /// <returns></returns>
        public static long _toTimestamp(this DateTime dt)
        {
            TimeSpan ts = dt.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0, 0);
            return Convert.ToInt64(ts.TotalSeconds);

        }

        /// <summary>
        /// 获取时间的星期
        /// 格式
        /// Remark：星期一
        /// StringExtend1:周一
        /// StringExtend2:一
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static RemarkAttribute _getDayOfWeek(this DateTime dt)
        {
            return ((DayOfWeekEnums)((int)dt.DayOfWeek))._GetRemark<RemarkAttribute>();
        }
    }
}
